import React, {Component} from 'react'
import {connect} from 'react-redux'
import {WrappedLoginForm} from '../../component/login'
import {queryParse} from '../../common/js/utils'
import './login.scss'

function mapStateToProps(state, props) {
  return {
    userInfo: state.get('userInfo')
  }
}

class LoginRouter extends Component {

  componentWillMount() {
    const search = queryParse(this.props.location.search)
    if (search.redirect && this.props.userInfo.get('status') === 1) {
      window.location.href = decodeURIComponent(search.redirect)
    }
  }

  render() {
    return (
      <div className="login-page">
        <div className="login-page-form">
          <WrappedLoginForm {...this.props} />
        </div>
      </div>
    )
  }
}

export default connect(mapStateToProps)(LoginRouter)